package kama;

import java.util.Scanner;

public class Test0046 {
}
class Main0046 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int space = scanner.nextInt();

        int[] consumes = new int[count];
        int[] values = new int[count];
        for (int i = 0; i < count; i++) consumes[i] = scanner.nextInt();
        for (int i = 0; i < count; i++) values[i] = scanner.nextInt();

        int[] dp1 = new int[space+1];
        int[] dp2 = new int[space+1];
        for (int i = 0; i < count; i++) {
            int consume = consumes[i];
            for (int j = 0; j <= space; j++) {
                int newSpace = j + consume;
                if ((newSpace <=space)&&(j==0||dp1[j]!=0)){
                    dp2[newSpace]=values[i]+dp1[j];
                }
                dp2[j]=Math.max(dp2[j],dp1[j]);
            }
            int[] temp = dp2;
            dp2 = dp1;
            dp1 = temp;
        }

        int ans = 0;
        for (int i = 0; i <= space; i++)
            ans=Math.max(ans,dp1[i]);
        System.out.println(ans);
    }
}
